"""快速插入100w条数据,
 增加IO操作时间,等获取到一定的量数据在进行数据插入,减少网络通讯次数.具体通讯几次,
 看executemany函数的上限一般是一条数据,暂满104000长度,进行通讯一次.
"""

import pymysql


list_ = []
for i in range(1000000):
    name = f"张三_{i}"
    list_.append(name)

print("数据追加到列表完成.")

db = pymysql.connect(host="localhost", user='debian-sys-maint', password='djknQTX2Egm1ZJVq', database='country',  port=3306, charset='utf8')
cur = db.cursor()
sql = "insert into students(name) values (%s)"
cur.executemany(sql, list_)
db.commit()

cur.close()
db.close()
print("数据插入完毕.")
    